package org.spbsu.timetable.model;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

public class Day {
	private static final Logger LOG = Logger.getLogger(Day.class);
	private Map<Integer, Lesson> lessons = new HashMap<>();
	private Integer pairsLimit;

	public Day(Integer pairsLimit) {
		this.pairsLimit = pairsLimit;
	}

	public Lesson addOccupation(Lesson occupation, Integer position) {
		if (position < 0 || position >= pairsLimit) {
			LOG.error("Position " + position + " is invalid.");

			return null;
		} else if (lessons.get(position) != null) {
			LOG.error("Position " + position + " has been already occupated.");

			return null;
		} else {
			lessons.put(position, occupation);

			return lessons.get(position);
		}
	}

	public Lesson getOccupation(Integer position) {
		return lessons.get(position);
	}
	
	public Map<Integer, Lesson> getPairs() {
		return lessons;
	}

	public Integer getPairsLimit() {
		return pairsLimit;
	}

	public void setPairsLimit(Integer pairsLimit) {
		this.pairsLimit = pairsLimit;
	}
	
	@Override
	public String toString() {
		String buffer = "";
		
		for (Integer position : lessons.keySet()) {
			buffer += position + " " + lessons.get(position) + "\n";
		}
		
		return buffer;
	}

}
